home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1185 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.8 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: "Bradd W. Szonye" <bradds@ix.netcom.com>
  3. Newsgroups: comp.std.c++
  4. Subject: RE: Use of standard exception classes
  5. Date: 21 Apr 1996 15:33:35 GMT
  6. Organization: Netcom
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <01bb2ee4.a9434580$65c2b7c7@Zany.localhost>
  9. References: <9604121530.AA08606@sun132.spd.dsccc.com> <3171C842.64BB@cyberramp.net>
  10. NNTP-Posting-Host: taumet.eng.sun.com
  11. X-Nntp-Posting-Host: det-mi3-05.ix.netcom.com
  12. X-Netcom-Date: Sat Apr 20  1:09:55 PM CDT 1996
  13. X-Newsreader: Microsoft Internet News
  14. Content-Length: 1804
  15. Originator: clamage@taumet
  16.  
  17.  
  18. On Monday, April 15, 1996, Bob Friesenhahn wrote...
  19. > Kevin Cline wrote:
  20. > > Can someone on the committee indicate whether it was the committee's
  21. > > intention for the standard exception class hierarchy to be used in
  22. > > general C++ programming, or whether the intention was for the standard
  23. > > exception class hierarchy to be reserved to the Standard C++ library?
  24. > > 
  25. > > Another developer on our team has asked
  26. > >   How can we be sure that ANSI C++ library callbacks work
  27. > >   correctly in the face of exceptions?  What if ANSI C++
  28. > >   library code catches *our* exception?
  29. > A further consideration is that often it is valuable to know what
  30. > body of code generated an exception.  If all exeptions are derived
  31. > from the same base class, then it will be impossible to tell if
  32. > an exception occurred in standard library code, user code, or some
  33. > third party library. An additional level of derivation could be
  34. > used to satisfy this requirement, but since the standard exception
  35. > classes have already been defined, there is no satisfactory place
  36. > to insert the additional derivation.
  37. > By using a different base class for each seperately maintained body
  38. > of code, it will be possible to provide handlers for each code body
  39. > with the additional maintenance expense of maintaining the additional
  40. > catch blocks.
  41. > Bob
  42.  
  43. I don't see this as a real problem (determining if the user's code
  44. generated the exception). Consider this:
  45.  
  46. class user_defined_exception: virtual public exception { ... };
  47. class user_logic_error: virtual public logic_error, virtual public
  48. user_definded_exception { ... };
  49.  
  50. ... catch (logic_error* e)
  51. {
  52.     if (dynamic_cast<user_defined_exception>(e)) ...
  53. }
  54.  
  55. This will tell you if the logic error you caught was one defined in your
  56. own code or somebody else's.
  57.  
  58.  
  59.  
  60.  
  61. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  62. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  63. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  64. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  65. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  66.